package com.fan.shop.businesslogic;

import org.apache.log4j.Logger;

import com.fan.shop.domain.TransactionReference;
import com.fan.shop.global.ShopGlobalVariables;
import com.fan.shop.process.ProcExec;
import com.fan.shop.services.TransactionReferenceService;

public class TransactionReferenceUpdateProcess extends ProcExec<Integer> {

	private static Logger logger = Logger.getLogger(TransactionReferenceUpdateProcess.class);
	private TransactionReferenceService transactionReferenceService;
	private String name;
	private String prefix;
	private String description;
	private int start;
	private int last;
	private int max;
	
	
	

	public static Logger getLogger() {
		return logger;
	}

	public static void setLogger(Logger logger) {
		TransactionReferenceUpdateProcess.logger = logger;
	}

	public TransactionReferenceService getTransactionReferenceService() {
		return transactionReferenceService;
	}

	public void setTransactionReferenceService(
			TransactionReferenceService transactionReferenceService) {
		this.transactionReferenceService = transactionReferenceService;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPrefix() {
		return prefix;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLast() {
		return last;
	}

	public void setLast(int last) {
		this.last = last;
	}

	public int getMax() {
		return max;
	}

	public void setMax(int max) {
		this.max = max;
	}

	public TransactionReferenceUpdateProcess() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public Integer processImpl() {
		if(transactionReferenceService.hasTransactionReference(name))
		{
			TransactionReference transactionReference = transactionReferenceService.getTransactionReference(name);
			transactionReference.setPrefix(prefix);
			transactionReference.setDescription(description);
			transactionReference.setStart(start);
			transactionReference.setLast(last);
			transactionReference.setMax(max);
			
			transactionReferenceService.updateTransactionReference(transactionReference);
			return ShopGlobalVariables.SUCCESS;
		}
		else
		{
			return ShopGlobalVariables.FAILED;
		}
	}

}
